package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IGreetingCardsSetService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.GreetingCardsSetCreateValidate;
import com.mdd.admin.validate.GreetingCardsSetUpdateValidate;
import com.mdd.admin.validate.GreetingCardsSetSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.GreetingCardsSetListedVo;
import com.mdd.admin.vo.GreetingCardsSetDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/cardSet")
@Api(tags = "贺卡设置管理")
public class GreetingCardsSetController {

    @Resource
    IGreetingCardsSetService iGreetingCardsSetService;

    @GetMapping("/list")
    @ApiOperation(value="贺卡设置列表")
    public AjaxResult<PageResult<GreetingCardsSetListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated GreetingCardsSetSearchValidate searchValidate) {
        PageResult<GreetingCardsSetListedVo> list = iGreetingCardsSetService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="贺卡设置详情")
    public AjaxResult<GreetingCardsSetDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        GreetingCardsSetDetailVo detail = iGreetingCardsSetService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "贺卡设置新增")
    @PostMapping("/add")
    @ApiOperation(value="贺卡设置新增")
    public AjaxResult<Object> add(@Validated @RequestBody GreetingCardsSetCreateValidate createValidate) {
        iGreetingCardsSetService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "贺卡设置编辑")
    @PostMapping("/edit")
    @ApiOperation(value="贺卡设置编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody GreetingCardsSetUpdateValidate updateValidate) {
        iGreetingCardsSetService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "贺卡设置删除")
    @PostMapping("/del")
    @ApiOperation(value="贺卡设置删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iGreetingCardsSetService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
